package com.bkgy.modular.configureRules.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.configureRules.dto.UnitTension2130Dto;
import com.bkgy.modular.configureRules.entity.UnitTension2130;
import com.bkgy.modular.configureRules.mapper.UnitTension2130Mapper;
import com.bkgy.modular.configureRules.service.UnitTension2130Service;
import com.bkgy.sys.common.entity.ResultData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @version 1.0
 * @ClassName UnitTension2130ServiceImpl
 * @date 2023/4/20 14:30
 */
@Service
public class UnitTension2130ServiceImpl extends ServiceImpl<UnitTension2130Mapper, UnitTension2130> implements UnitTension2130Service {
    @Resource
    private UnitTension2130Mapper unitTension2130Mapper;

    @Override
    public ResultData queryUnitTension2130(JSONObject jsonObject) {
        Integer pageIndex = jsonObject.getInteger("pageIndex");
        Integer pageSize = jsonObject.getInteger("pageSize");
        if (pageIndex == null || pageSize == null) {
            return ResultData.ResultDataFaultSelf("分页参数不能为空",-1);
        }

        PageHelper.startPage(pageIndex,pageSize);
        List<UnitTension2130> list = unitTension2130Mapper.selectList(null);
        PageInfo<UnitTension2130> pageInfo = new PageInfo<>(list);
        return ResultData.ResultDataFaultSelf("操作成功",pageInfo);
    }

    @Override
    public ResultData updateUnitTension2130(UnitTension2130Dto dto) {
        Double id = dto.getId();
        if (id == null) {
            return ResultData.ResultDataFaultSelf("参数有误,请检查参数",-1);
        }
        Double yp_class = dto.getYp_class();
        Double width_class = dto.getWidth_class();
        Double thickness_class = dto.getThickness_class();
        Double s1_entry = dto.getS1_entry();
        Double s1_s2 = dto.getS1_s2();
        Double s2_s3 = dto.getS2_s3();
        Double s3_s4 = dto.getS3_s4();
        Double s4_s5 = dto.getS4_s5();
        Double s5_tr = dto.getS5_tr();

        LambdaQueryWrapper<UnitTension2130> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UnitTension2130::getId,id);

        UnitTension2130 unitTension2130 = unitTension2130Mapper.selectOne(queryWrapper);
        if (unitTension2130 != null) {
            unitTension2130.setYp_class(yp_class);
            unitTension2130.setWidth_class(width_class);
            unitTension2130.setThickness_class(thickness_class);
            unitTension2130.setS1_entry(s1_entry);
            unitTension2130.setS1_s2(s1_s2);
            unitTension2130.setS2_s3(s2_s3);
            unitTension2130.setS3_s4(s3_s4);
            unitTension2130.setS4_s5(s4_s5);
            unitTension2130.setS5_tr(s5_tr);
            int flag = unitTension2130Mapper.update(unitTension2130, queryWrapper);
            if (flag == 1) {
                return ResultData.ResultDataFaultSelf("操作成功",1);
            }
        }
        return ResultData.ResultDataFaultSelf("操作失败",-1);
    }
}
